/**
 * 个人中心模块
 */
define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";

	var pageSize=10;
	
	require("../../custom/base/component-core.js");
	
	require("../../custom/base/component-page.js");
	
	require("../../custom/base/component-md5.js");
	
	var validate = require("../../custom/base/component-validate.js");
	
	var base = require("../../custom/base/component-base.js");
	
	base.init(base);
		
	var async = require("../../custom/base/component-async.js");
	
	var upload=require("../../custom/base/component-upload.js");
	
	
	//设置订单状态
	exports.setOrderStatusId=function(orderStatusId,orderStatusName){
		
		this.orderStatusId=orderStatusId;
		
		$("#orderStatusName").html(orderStatusName);
		
		$(".btn-group").removeClass("open");
		
		exports.setOrderCurrentPage(1);
		
		exports.getMyOrder();
	};
	
	//获取订单状态
	exports.getOrderStatusId=function(){
		
		return this.orderStatusId==null?"":this.orderStatusId;
		
	};
	
	//初始化函数
	exports.init=function(m){
		
		window.$ldh_user=m;
		
		base.setFromPage(base.getParameter("fromPage"));
		
	};
	
	//设置订单列表页码
	exports.setOrderCurrentPage=function(orderCurrentPage){
		
		this.orderCurrentPage=orderCurrentPage;
		
	};
	
	//获取订单列表页码
	exports.getOrderCurrentPage=function(){
		
		return this.orderCurrentPage==null?1:this.orderCurrentPage;
		
	};
	
	
	//查询我的订单
	exports.getMyOrder=function(){
		
		//加这段是为了适应在微信里使用支付宝支付时丢失cookie
		var userId=base.getParameter("userId");
		var loginSign=base.getParameter("loginSign");
		if(!validate.isNull(userId) && !validate.isNull(loginSign)){
			
			base.setCookie("userId",userId);
			base.setCookie("loginSign",loginSign);
		}
			
			
		base.showLoading();
		
		var params = {
				userId : base.getCookie("userId"),
				statusId:exports.getOrderStatusId(),
				pageSize : pageSize,
				currentPage : exports.getOrderCurrentPage(),
				"loginSign":$ldh_base.getCookie("loginSign"),
				"sign":MD5($ldh_base.getCookie("loginSign")+base.getCookie("userId"))
					
					
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx+"/shopapp/Order/getMyOrderGoods.do", params));
												
						
						if(data["code"]==1){
							
							var htmlStr="";
							
							
							
							for(var i=0;i<data["orders"].length;i++){

											
											htmlStr += '<div class="orderlist_block" onClick=window.location.href="'+ctx+'/h5/orderDetail/'+data["orders"][i]["orderId"]+'.shtml">';
											htmlStr += '<ul>';
											htmlStr += '<li class="clearfix"><span>订单号：'+data["orders"][i]["orderId"]+'</span>';
											
											if(data["orders"][i]["orderStatusName"]=="交易关闭"){
												htmlStr += '<span class="color_gray float-right">交易关闭</span>';
											}else if(data["orders"][i]["orderStatusName"]=="待付款" || data["orders"][i]["orderStatusName"]=="待发货"){
												htmlStr += '<span class="main_color float-right">'+data["orders"][i]["orderStatusName"]+'</span>';
											}else{
												htmlStr += '<span class="color_green float-right">'+data["orders"][i]["orderStatusName"]+'</span>';
											}
											htmlStr += '</li>';
											htmlStr += '<li class="orderlist_time"><span>下单时间：</span><span>'+data["orders"][i]["orderTime"]+'</span></li>';
											htmlStr += '<li>';
											//htmlStr += '<a data-transition="none" href="?id=1#ldhVieworder">';
											htmlStr += '<h3>'+data["orders"][i]["shopName"]+'</h3>';
											htmlStr += '<p class="orderlist_img_box">';
											
											for(var j=0;j<data["orders"][i]["picList"].length;j++){	
												
												var picDefault=data["orders"][i]["picList"][j];
												
												
												if(validate.isNull(picDefault)){
													
													picDefault = ctx+"/v1/img/default_234_220.png";

												}else{
													
													picDefault=fileOpenUrl+picDefault;

												}
												
												htmlStr += '<span class="orderlist_img"><img src="'+picDefault+'" /></span>';
												
												/*htmlStr += '<tr>';
												//htmlStr += '<td class="text-center"><div class="ldh-orderpic"><a class="pic" href="####"><img src="'+picDefault+'" alt="查看宝贝详情" /></a></div></td>';
												//htmlStr += '<td class="text-left"><a class="text" href="#" target="_blank">'+data["orders"][i]["goods"][j]["merchandiseName"]+'</a></td>';
												htmlStr += '<td class="text-center"><div class="ldh-orderpic"><img src="'+picDefault+'" alt="查看宝贝详情" /></div></td>';
												htmlStr += '<td class="text-left">'+data["orders"][i]["goods"][j]["merchandiseName"]+'</td>';
												htmlStr += '<td>¥'+data["orders"][i]["goods"][j]["price"]+'</td>';
												htmlStr += '<td>'+data["orders"][i]["goods"][j]["nums"]+'</td>';
												htmlStr += '</tr>';*/
											}

											htmlStr += '</p>';
											//htmlStr += '</a>';
											htmlStr += ' </li>';
											htmlStr += '<li class="orderlist_money clearfix">';
											htmlStr += '<span>金额：</span><strong class="main_color">'+Number(data["orders"][i]["totalAmount"]).toFixed(2)+'元</strong>';
											htmlStr += '</li>';
											htmlStr += '</ul>';
											htmlStr += '</div>';
		                      
		                      
											$("#ldhOrderlist .orderlist").append(htmlStr);
											htmlStr="";
							}
							
							var totals=data["totalcount"];
							var pages=data["totalpage"];
								
							if(exports.getOrderCurrentPage()<pages){
								$("#ldhOrderlist .checkmore").show();
							}else if(exports.getOrderCurrentPage()==pages && pages>1){
								$("#ldhOrderlist .checkmore").show();
								$("#ldhOrderlist .checkmore").html("已到最后一页");
								$("#ldhOrderlist .checkmore").removeAttr("onclick");
							}
							
							
 
						}else if(data["code"]=="-10001"){
							
							alert(data["message"]);
							
						}
						
						base.cancelLoading();
						
		}))().start();
		
	};
	
	/**
	 * 加载更多
	 */
	exports.loadMoreMyOrderList=function(){
		
		$("#ldhOrderlist .checkmore").hide();
		
		exports.setOrderCurrentPage(exports.getOrderCurrentPage()+1)
		
		exports.getMyOrder();
	}
	
	//订单详情
	exports.getOrderDetail=function(){
		
		var orderId=base.getParameter("orderId");

		$("#ldhVieworder .mine_link span").html("");
		$("#ldhVieworder .vieworder_block").html('');
		$("#ldhVieworder .merchandise_detail_block ul").html("");
		$("#ldhVieworder .box_block .orderlist_money").html('');
		$("#ldhVieworder .header_fixed h1").html('');
		$("#ldhVieworder .top_tips p").html('');
		base.showLoading();
		
		var params = {
				 userId:$ldh_base.getCookie("userId"),
				 orderId:orderId,
				"loginSign":$ldh_base.getCookie("loginSign"),
				"sign":MD5($ldh_base.getCookie("loginSign")+orderId)
		};
		
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopapp/Order/getOrder.do", params));
						
						
						if(data["code"]==1){
							
							//订单操作
							var orderButtonHtmlStr="";
							
							if(data.allowPay=="1"){
								orderButtonHtmlStr += '<button type="button" onClick=$ldh_user.goPay("'+data["orderId"]+'","'+data["totalAmount"]+'") data-role="none">去付款</button>';
							}
							
							if(data.allowRefuseGoods=="1"){
								orderButtonHtmlStr += '<button type="button" data-role="none" onClick=$ldh_user.rejectReason("refuse","拒绝收货","4","'+data.orderId+'")>拒绝收货</button>';
							}else{
								if(data.allowCancel=="1"){
									orderButtonHtmlStr += '<button type="button" data-role="none" onClick=$ldh_user.rejectReason("cancel","取消订单","2","'+data.orderId+'")>取消订单</button>';
								}
							}
							
							if(data.allowRemindToShop=="1"){
								orderButtonHtmlStr += '<button type="button" data-role="none" onClick=$ldh_user.remindToShop("'+data.orderId+'","是否确认提醒商家发货？")>提醒商家发货</button>';
							}
							
							if(data.allowApplay=="1"){
								orderButtonHtmlStr += '<button type="button" data-role="none" onClick=$ldh_user.rejectReason("apply","客服介入","6","'+data.orderId+'")>申请客服介入</button>';
							}
							
							if(data.allowAcceptGoods=="1"){
								orderButtonHtmlStr += '<button type="button" data-role="none" onClick=$ldh_user.processOrder("","5","'+data.orderId+'","是否确认收货？")>确认收货</button>';
							}
							
							$("#ldhVieworder .box_block .orderlist_money").html('<p>'+orderButtonHtmlStr+'</p>');
							
							
							
							//订单状态
							
							var statusStr="";
						
							if(data.paymentId=="2"){
								//在线支付
								if(data.statusId == '1'){
									//待发货
									statusStr="待发货";
								}else if(data.statusId == '2'){
									//待收货
									statusStr="待收货";
								}else if(data.statusId == '3'){
									//交易成功
									statusStr="交易成功";
									
								}else if(data.statusId == '4'){
									//交易关闭
									
									statusStr="交易关闭";
								}else if(data.statusId == '5'){
									//代付款
									statusStr="代付款";
								
									
								}else if(data.statusId == '6'){
									//拒接收货
								
									statusStr="拒接收货";
								}else if(data.statusId == '7'){
									//客服调解
									statusStr="客服调解";
								}
								
							}else{
								
								//货到付款
								if(data.statusId == '1'){
									//待发货
									statusStr="待发货";
								}else if(data.statusId == '2'){
									//待收货
									statusStr="待收货";
								}else if(data.statusId == '3'){
									//交易成功
									statusStr="交易成功";
									
								}else if(data.statusId == '4'){
									//交易关闭
									statusStr="交易关闭";
								}
								
							}
							
							$("#ldhVieworder .header_fixed h1").html("我的订单详情");
							var htmlStr="";
							htmlStr += '<li class="clearfix"><span>订单号：'+data["orderId"]+'</span>';
							
							if(data.statusName=="交易关闭" || data.statusName=="待付款" || data.statusName=="待发货"){
								htmlStr += '<span class="main_color float-right">'+data.statusName+'</span>';
							}else{
								htmlStr += '<span class="color_green float-right">'+data.statusName+'</span>';
							}
							htmlStr += '</li>';
							htmlStr += '<li class="orderlist_time"><span>下单时间：</span><span>'+data["orderDate"]+'</span></li>';
							
							$("#ldhVieworder .order_detail_block ul").html(htmlStr);
							
							
							if(!validate.isNull(data.timeoutMessage)){
								
								$("#ldhVieworder .top_tips").show();
								$("#ldhVieworder .top_tips p").html(data.timeoutMessage);
							}else{
								$("#ldhVieworder .top_tips").hide();
							}
							 
								$("#ldhVieworder .mine_link span").html("商家:"+data.shopName);
								
								var shopName=encodeURI(data.shopName);
								$("#ldhVieworder .mine_link li").attr("onClick","window.location.href='"+ctx+"/h5/shopIndex/"+data.shopId+".shtml'");
								//shopId="+data.shopId+"
								//onClick=window.location.href=\"?orderId='+data["orders"][i]["orderId"]+'#ldhVieworder\"
								
							 	$("#ldhVieworder .vieworder_block").html('');
							    $("#ldhVieworder .vieworder_block").append('<p><span>收件人：</span><span>'+data.shipName+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p><span>电话：</span><span>'+data.shipMobile+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p><span>地址：</span><span>'+data.shipAddress+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p class="orderlist_time"><span>送达时间：</span><span>'+data.shipTime+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p><span>支付方式：</span><span>'+data.paymentName+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p><span>订单编号：</span><span>'+data.orderId+'</span></p>');
							    $("#ldhVieworder .vieworder_block").append('<p><span>备注：</span><span>'+data.memo+'</span></p>');

								
								var htmlStr="";
								
								for(var i=0;i<data.items.length;i++){
									
												
												var picDefault=data.items[i]["picDefault"];
												
												
												if(validate.isNull(picDefault)){
													
													picDefault = ctx+"/v1/img/default_234_220.png";

												}else{
													
													picDefault=fileOpenUrl+picDefault;

												}
												

											htmlStr += ' <li class="clearfix" onClick=window.location.href="'+ctx+'/h5/merDetail/'+data.items[i]["merchandiseId"]+'.shtml">';
											htmlStr += '<div class="store_goods_pic"><a data-transition="none" href=><img src="'
													+ picDefault
													+ '"/></a></div>';
											htmlStr += '<div class="store_goods_info">';
											htmlStr += '<h3>'
													+ data.items[i]["merchandiseName"]
													+ '</h3>';
											htmlStr += '<p><span>¥'
													+ data.items[i]["price"]
													+ '/'
													+ data.items[i]["unitName"]
													+ '</span>&nbsp;&nbsp;x&nbsp;&nbsp;<span>'
													+ data.items[i]["nums"]
													+ '</span></p>';
											htmlStr += '<p><span>金额：</span><span class="main_color">'
													+ data.items[i]["amount"]
													+ '元</span></p>';
											htmlStr += '</div>';
											htmlStr += ' </li>';
												
								
								}
								 $("#ldhVieworder .merchandise_detail_block ul").html(htmlStr);
								
								 $("#ldhVieworder .merchandise_detail_block ul").append('<li class="orderlist_money"><span>总金额：</span><strong class="main_color">'+data.totalAmount+'元</strong></li>');   
								
						}
						
						base.cancelLoading();

			}))().start();
				
						
		
		
	};
	
	//拒绝收货
	exports.rejectReason=function(id,title,processCode,orderId){	
		
		
			
		  $ldh_user.processOrder(id,processCode,orderId,"是否确认"+title+"?");
		
		
/*		  var btnleft="确定";
		  var btnright="取消";
		  var changepwd=
			  '<div id="'+id+'" class="alert_div">' +
				   '<div class="alert_div_con" style="min-height:0px;">' +
					   '<div class="close_alert close_alert_btn"></div>'+
					   '<div class="alert_header">'+title+'</div>'+
					   '<div class="alert_body clearfix">'+
					   		'<dl>'+
								'<dt id="reasonList">'+title+'原因</dt>'+
								'<dd><input type="radio" name="reject" class="radio" checked="checked" /><span class="click_span">商品有问题！</span></dd>'+
								'<dd><input type="radio" name="reject" class="radio" /><span class="click_span">送货太迟！</span></dd>'+
								'<dd><input type="radio" name="reject" class="radio" /><span class="click_span">商品损坏！</span></dd>'+
							'</dl>'+
							'<dl id="otherReasonDiv" style="display:none;">'+
								'<dt>其他原因</dt>'+
								'<dd><textarea class="textarea" id="reasonContent"></textarea></dd>'+
							'</dl>'+
							'<dl id="reasonImageDiv" style="display:none;">'+
								'<dt>上传证据</dt>'+
								'<dd><span id="upLoadReasonButton" ></span>&nbsp;<span id="upload_loading_upLoadReasonButton" style="display:none;"><img src="/shop/v1/img/upload_loading.gif" alt="头像"></span></dd>'+
								'<dd><div class="user-thumb-pic2"><ul id="reasonImageList"></ul></div></dd>'+
							'</dl>'+
					   '</div>'+
					   '<div class="ldh-waiting" id="order_process_loading" style="height:50px;display:none;" ></div>'+
					   '<div class="alert_footer">'+
					    '<button class="btn-green" type="button" onClick=$ldh_user.processOrder("'+id+'","'+processCode+'","'+orderId+'","是否确认'+title+'？") >确定</button> &nbsp'+
	               		'<button class="btn-main close_alert_btn" type="button">取消</button> &nbsp'+
					    '</div>'+
				   '</div>' +				   
			  '</div>'+'<div class="alert_div_bg"></div>';
		  $(changepwd).appendTo("body");
		  $("#"+id).find(".close_alert_btn").click(function(){
			  $("body").find(".alert_div_bg").remove();
			  $("#"+id).remove();		  		
		  });	  
		  
		  upload.ldh_upload("upLoadReasonButton","/order/reason","uploadReasonCallBack");
		  
			var params = {
					orderId:orderId,
					processCode:processCode
			};
			
			
			eval(
						Wind.compile("async", function() {

							var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/Order/getReasonList.do", params));
							
							
							if(data["code"]==1){		
								
								var htmlStr="";
								for (var i = 0; i < data["reasonList"].length; i++) {
									
									if(i==0){
										htmlStr += '<dd><input type="radio" name="reasons" class="radio" value="'+data["reasonList"][i]["reasonCode"]+'" checked="checked" /><span class="click_span">'+data["reasonList"][i]["reasonName"]+'</span></dd>';

									}else{
										
										htmlStr += '<dd><input type="radio" name="reasons" class="radio" value="'+data["reasonList"][i]["reasonCode"]+'" /><span class="click_span">'+data["reasonList"][i]["reasonName"]+'</span></dd>';

									}
								}
								
								$("#reasonList").after(htmlStr);
								
								$('.alert_body dl:eq(0) input:radio').click(function(e) {
									var reasonId=$(this).val();
									if(reasonId=="10"){
										$("#otherReasonDiv").css("display","block");
									}else{
										$("#otherReasonDiv").css("display","none");
									}
									
								});
								
								if(processCode=="6"||processCode=="4"){
									$("#reasonImageDiv").css("display","block");
								}else{
									$("#reasonImageDiv").css("display","none");
								}
								
							}
							
							
							

			}))().start();*/
		  
	};
	
	//订单处理
	exports.processOrder=function(id,processCode,orderId,tip){
		
		if(processCode=="支付"){
			window.location.href="";
		}
		
		var gnl=confirm(tip);

		if (gnl == true) {
			
			var reason=1;
			var content ="";
			var fileUrl="";//附件路径
			var channelId="";
			var processer="1";//处理人,1为用户
		/*	if($("#reasonImageDiv").css("display")=="block"){
				for (var i = 0; i <= $("#reasonImageDiv li").length; i++) {
					
					fileUrl+=$("#reasonImageDiv li img").attr("source_src")+",";
				}
			}
			*/
				
			var params={
					"processCode" : processCode,
					"orderId" : orderId,
					"reason" : reason,
					"content" : content,
					"fileUrl" : fileUrl,
					"processer":processer,
					"userId":$ldh_base.getCookie("userId"),
					"loginSign":$ldh_base.getCookie("loginSign"),
					"sign":MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+orderId+processCode+reason+fileUrl+content+channelId)
			};

			base.showLoading();
			
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopapp/Order/processOrder.do", params));
						
						
						if(data["code"]==1){		
							
							if(data["code"]=="1"){
								
								exports.getOrderDetail(orderId);
								
							}else{
								
								alert("订单处理失败:"+data.message);
								
							}
							
							
						}
						
						
						base.cancelLoading();
						
						
						

					}))().start();
			
			
			
		};
	};
	
	//提醒商家发货
	exports.remindToShop=function(orderId,tip){
		
		var gnl=confirm(tip);

		if (gnl == true) {
			
				var params={
						 userId:$ldh_base.getCookie("userId"),
						 orderId:orderId,
						"loginSign":$ldh_base.getCookie("loginSign"),
						"sign":MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+orderId)
				};
				eval(
						Wind.compile("async", function() {
	
							var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopapp/Remind/remindToShop.do", params));
							
							
							if(data["code"]==1){		
								
								alert("提醒商家发货成功");
								
							}else{
								
								alert("提醒商家发货失败");
							}
	
				}))().start();
		}
	};

	//去付款
	exports.goPay=function(orderId,totalAmount){
		
		//get2post(ctx+"/v1/pages/order/pay.jsp?order="+orderId+"&orderIds="+orderId+"&totalMoney="+Number(totalAmount).toFixed(2));
		
		
		//base.showDiv("?orderId="+orderId+"&orderAmount="+Number(totalAmount).toFixed(2)+"#ldhOnlinePay");
		
		window.location.href=ctx+'/h5/onlinePay/'+orderId+'/'+Number(totalAmount).toFixed(2)+'.shtml';

		
	};
	
	//上传理由回调函数
	uploadReasonCallBack=function(dataObj){
		
		var dataPath = "";
		if(dataObj.code == "1"){
			for(var i=0;i<dataObj.files.length;i++){
				if(dataObj.files[i].repCode=="1"){
					dataPath = dataObj.files[i].path;
					/*$("#ucenter_iconUrl").val(dataPath);
					$("#ucenter_iconUrl").attr("src", fileOpenUrl + dataPath);
					$("#div_myinfo_tip").show();
					$("#myinfo_tip").html("上传头像成功,请保存")*/;
				
					//$("#iconUrlInput").val(dataPath);
					$("#reasonImageList").append('<li><a class="lightboxTrigger" href="'+ctx+'/v1/img/lit_03.png"><img src="'+fileOpenUrl + dataPath+'" source_src="'+dataPath+'"></a><p onclick="$ldh_user.deleteReasonPic(this)">删除</p></li>');
					
				}else{
					
				}
			}
			
			
		}else{
			
			//上传失败
			
		}
		
		$("#upload_loading_upLoadReasonButton").hide();
	//	task("#div_myinfo_tip").start();
		
	};
	
	//删除理由图片
	exports.deleteReasonPic=function(obj){
		
		$(obj).parent().remove();
	};
	
	
	//设置收藏列表页码
	exports.setFavorCurrentPage=function(favorCurrentPage){
		
		this.favorCurrentPage=favorCurrentPage;
		
	};
	
	//获取收藏列表页码
	exports.getFavorCurrentPage=function(){
		
		return this.favorCurrentPage==null?1:this.favorCurrentPage;
		
	};
	
	//收藏商家列表
	exports.getMyFavorShop=function(){
		
		
		var params = {
				currentPage:exports.getFavorCurrentPage(),
				pageSize :pageSize,
				 userId:$ldh_base.getCookie("userId"),
				"loginSign":$ldh_base.getCookie("loginSign"),
				"sign":MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId"))
		};
		base.showLoading();
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopapp/MyShop/getMyShops.do", params));
						
						
						if(data["code"]==1){
		
							var htmlStr="";
							
							for (var i = 0; i < data["shops"].length; i++) {
								
								
								var introduce=data["shops"][i]["introduce"];
								
								var minAmount = data["shops"][i]["minAmount"];
								
								var businessStatus = data["shops"][i]["businessStatus"];

								var score=(data["shops"][i]["score"]/5)*100;
								
								var businessHours=data["shops"][i]["businessHours"];
								
								var range= data["shops"][i]["range"];
								
								var shopName=encodeURI(data["shops"][i]["shopName"]);
								
								if(validate.isNull(introduce))
									introduce="暂无";
								
								if(validate.isNull(businessHours))
									businessHours="全天";
								
							
								
								if(minAmount=="" || minAmount=="0"){
									minAmount="起送金额不限";
								}else{
									minAmount=minAmount+"元起送";
								}

								if(range=="" || range=="0"){
									range="配送范围不限";
								}else{
									range=range/1000;
									range=range+"km内配送";
								}
											htmlStr += '<li onClick=window.location.href="'+ctx+'/h5/shopIndex/'+data["shops"][i]["shopId"]+'.shtml">';
											if(data["shops"][i]["logoUrl"]!="" && data["shops"][i]["logoUrl"].indexOf(".")>0){
												htmlStr += '<div class="store_list_logo"><img src="'+fileOpenUrl+data["shops"][i]["logoUrl"]+'"/></div>';
											}else{
												htmlStr += '<div class="store_list_logo"><img src="'+ctx+'/v1/img/default_234_220.png"/></div>';
											}
											
											htmlStr += '<div class="store_list_info">';
											htmlStr += '<h3>'+data["shops"][i]["shopName"]+'</h3>';
											htmlStr += '<p><span class="store_star"><em style="width:'+score+'%"></em></span><span>'+base.getSpeHtml(data["shops"][i]["speId"])+'</span></p>';
											htmlStr += '<p><span>'+minAmount+'</span>&nbsp;&nbsp;|&nbsp;&nbsp;<span>'+range+'</span></p>';
											htmlStr += '</div>';                    
											htmlStr += '</li>';
											
											
								}
								
							
							$("#ldhCollectList .store_list ul").html(htmlStr);
							
						/*	if(validate.isNull(htmlStr)){
								
							
								
							}else{
								
							
								$("#shopList").html(htmlStr);
								
								 $('#myfavor-footPage').ldh_pagination_shoplist(data["pageSize"],data["currentPage"],data["totals"],data["pages"],{  
									 
									 changePageCallback:function(pageSize,page){  
										
										 exports.setFavorCurrentPage(page);
										 
										 exports.getMyFavorShop();
									 },
									 changePageSizeCallBack:function(pageSize){
									 } 
						         }); 
							}*/

						}
						
						base.cancelLoading();
						
						
					}))().start();
			
	};
	
	//查询我的个人信息
	exports.getMyInfo=function(){
		
		
		base.showLoading();
		
		var params = {
			userId:$ldh_base.getCookie("userId"),
			loginSign:$ldh_base.getCookie("loginSign"),
			sign:MD5($ldh_base.getCookie("userId")+$ldh_base.getCookie("loginSign"))
		};
		
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopapp/User/getUserInfo.do", params));
									
						if(data["code"]==1){
							
							$("#ldhMine .mine_name").html(data["RsUser"]["userName"]);
							$("#ldhMine .mine_neck .ui-block-a em").html(data["orderCount"]);
							$("#ldhMine .mine_neck .ui-block-b em").html(data["memberCount"]);
							if(!validate.isNull(data["RsUser"]["iconUrl"])){
								
								$("#ldhMine .mine_logo img").attr("src", fileOpenUrl + data["RsUser"]["iconUrl"]);
							}
							
						}else if(data["code"]=="-4444"){
							
							window.location.href=ctx+"/h5/login.shtml?fromPage=ldhMine";
							
						}
						
						base.cancelLoading();
						
						
		}))().start();
		
	};
	
	//更新个人信息
	exports.updateUserInfo=function(){
		
		var email=$("#ucenter_email").val();
		
		$("#div_myinfo_tip").show();
		
		if(!validate.isNull(email)){
			
			if(!validate.isEmail(email)){
				
				
				$("#myinfo_tip").html("邮箱格式不正确");
								
				return;
			}
			
			
		}
		
		$("#myinfo_tip").html("正在保存...");
		
		var params={
				userName:$("#ucenter_userName").text(),
				realName:$("#ucenter_realName").val(),
				email:email,
				iconUrl:$("#ucenter_iconUrl").val()
				
		};
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/User/updateUserInfo.do", params));
					
					$("#div_myinfo_tip").show();
					
					if(data["code"]==1){
						
						
						
						$("#myinfo_tip").html("保存成功");
						
						$("#userIndex_iconUrl,#iconUrl").attr("src",fileOpenUrl+$("#ucenter_iconUrl").val());
						
						
						
					}else{
						
						
						$("#myinfo_tip").html(data["message"]);
						
					}
					task("#div_myinfo_tip").start();
					
					
				}))().start();
	};
	
	var boundx,boundy;
	//上传头像回调函数
	uploadHeadImageCallBack=function(dataObj){
		
		var dataPath = "";
		if(dataObj.code == "1"){
			for(var i=0;i<dataObj.files.length;i++){
				if(dataObj.files[i].repCode=="1"){
					dataPath = dataObj.files[i].path;
					//$("#ucenter_iconUrl").val(dataPath);
					//$("#ucenter_iconUrl").attr("src", fileOpenUrl + dataPath);
					
					$("#upLoadFileButton").appendTo($(".ldh-mypic-btn"));
					$("#ucenter_preview_iconUrl_div").html('<img id="ucenter_preview_iconUrl" src="'+fileOpenSourceUrl + dataPath+'" alt="头像" />');
					$("#preview_iconUrl_90").attr("src", fileOpenSourceUrl + dataPath);
					$("#preview_iconUrl_50").attr("src", fileOpenSourceUrl + dataPath);
					$("#preview_iconUrl_30").attr("src", fileOpenSourceUrl + dataPath);
					 // Invoke Jcrop in typical fashion
				      $('#ucenter_preview_iconUrl').Jcrop({
				    	onChange: updatePreview,
				  		onSelect: updatePreview,
				  		aspectRatio: 1,
				  		allowSelect:true
				      },function(){

				    	var bounds = this.getBounds();
				  		boundx = bounds[0];
				  		boundy = bounds[1];
				  	    //this.animateTo([100,100,100,100]);
				  	   // $('#preview-pane_90,#preview-pane_50,#preview-pane_30').appendTo(this.ui.holder);
				  	  
				      });
				      
					//$("#div_myinfo_tip").show();
					
					//$("#myinfo_tip").html("上传头像成功,请保存");
				
					//$("#iconUrlInput").val(dataPath);
				}else{
					
				}
			}
			
			
		}else{
			
			//上传失败
			//$("#myinfo_tip").html("上传头像失败");
		}
		
		$("#upload_loading_upLoadFileButton").hide();
		
		//task("#div_myinfo_tip").start();
		
	};

	function updatePreview(c){
		if (parseInt(c.w) > 0) {
			
			//c.x+","+c.y+","+c.w+","+c.h;	
			$("#x_upLoadFileButton").val(c.x);
			$("#y_upLoadFileButton").val(c.y);
			$("#width_upLoadFileButton").val(c.w);
			$("#height_upLoadFileButton").val(c.h);
			
			var rx = 90 / c.w;
			var ry = 90 / c.h;
			$('#preview_iconUrl_90').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
			rx = 50 / c.w;
			ry = 50 / c.h;
			$('#preview_iconUrl_50').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
			rx = 30 / c.w;
			ry = 30 / c.h;
			$('#preview_iconUrl_30').css({
				width: Math.round(rx * boundx) + 'px',
				height: Math.round(ry * boundy) + 'px',
				marginLeft: '-' + Math.round(rx * c.x) + 'px',
				marginTop: '-' + Math.round(ry * c.y) + 'px'
			});
		}
	};
	
	//账户安全
	exports.setAccountSafe=function(){
		
		$("#div_account_safe_tip").hide();
		
		$("#div_account_safe_mobile_tip").hide();
		
		$(".ldh-myCenterR").hide();
		
		$("#ldh-account-safe").show();
		
		$(".ldh-myCenter-btm li a").css("color","#9a8072");

		$(".ldh-index-safety").css("color","#ed5d3a");
		
	};
	
	//重设登录密码
	exports.resetLoginPwd=function(){
		
			var old_password=$("#ucenter_old_password").val();
			
			var new_password=$("#ucenter_new_password").val();
			
			var r_new_password=$("#ucenter_r_new_password").val();
			
			$("#div_account_safe_tip").show();
			
			if(validate.isNull(old_password)){
				
				$("#div_account_safe_tip span").html("当前密码不能为空");
				
				return;
			}

			if(!validate.isLoginPassword(new_password)){
				
				$("#div_account_safe_tip span").html("新密码为6-20位数字，字母，符号组合，请重新输入");
				
				return;
			}
			
			if(r_new_password!=new_password){
				
				$("#div_account_safe_tip span").html("两次密码不一致");
				
				return;
			}
		
			var params={
				oldPwd:MD5(old_password),
				newPwd:MD5(new_password)
					
			};
			
			eval(
					Wind.compile("async", function() {

						var data = $await(async.DDF_AsyncRequest("POST", ctx + "/shopweb/AccountSafe/resetLoginPwd.do", params));
						
						if(data["code"]==1){
							
							$("#div_account_safe_tip span").html("重设密码成功");
							
						}else{
							$("#div_account_safe_tip span").html(data["message"]);
							
						}
						
						$("#ucenter_old_password").val("");
						
						$("#ucenter_new_password").val("");
						
						$("#ucenter_r_new_password").val("");
						
						task("#div_account_safe_tip").start();
						
						
					}))().start();
	};
	
	
	//验证手机号
	exports.validateMobile=function(btnId){
		
		var mobile = $("#ucenter_new_mobile").val();
		
		$("#div_account_safe_mobile_tip").show();
		
		if(!validate.isMobile(mobile)){
			
			$("#div_account_safe_mobile_tip span").html("请填写正确的手机号码");
			
			return;
		}
		
		$(btnId).attr("disabled", "disabled");

		//base.showLoading(btnId,20,true);
		
		var params={
				
				"mobile":mobile
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/validateMobile.do", params));
			
			if(data.code == "1"){
				//未注册,发送验证码
				$("#div_account_safe_mobile_tip").hide();
				
				sendMessage(mobile,btnId);
			}else{
				
				$("#div_account_safe_mobile_tip span").html(data.message);
				
				$(btnId).val("免费获取验证码");
				
				//如果该手机已注册,则可以马上重新验证
				$(btnId).attr("disabled", false);
			}

		}))().start();
		
	};
	
	
	//发送短信验证码
	function sendMessage(mobile,btnId){
		
		var params={
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/sendValidateCode.do", params));

			if(data.code == "1"){
				
				$("#div_account_safe_mobile_tip").show();
				
				$("#div_account_safe_mobile_tip span").html("验证码已发送,请注意查收");
				
				task("#div_account_safe_mobile_tip").start();
				
				task_mobile(btnId).start();
				
				
				
			}else{
				
				//如果获取验证码失败,则可以马上重新获取
				$(btnId).attr("disabled", false);
				
				$(btnId).val("免费获取验证码");
				
				$("#div_account_safe_mobile_tip span").html(data.message);
			
			}

		}))().start();
	}
	
	//绑定手机
	exports.setMobile=function(){
		
		var params={
				"mobile":$("#ucenter_new_mobile").val(),
				"validateCode":$("#ucenter_validate_code").val()
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/AccountSafe/setMobile.do", params));

			$("#div_account_safe_mobile_tip").show();
			
			if(data.code == "1"){
				
				$("#div_account_safe_mobile_tip span").html("绑定成功");
				
				$("#ucenter_new_mobile").val("");
				
				$("#ucenter_validate_code").val("");
				
				
			}else{
				
				$("#div_account_safe_mobile_tip span").html(data.message);
			
			}
			
			task("#div_account_safe_mobile_tip").start();
			
		}))().start();
		
	};

	//查询收货地址列表
	exports.getMyAddressList=function(){
				
		var params={
				userId:$ldh_base.getCookie("userId"),
				currentPage:1,
				pageSize:10,
				loginSign:$ldh_base.getCookie("loginSign"),
				sign:MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+10+""+1)
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Address/addressList.do", params));

			if(data.code == "1"){
				
				var htmlStr="";
			
				for(var i=0;i<data["addressList"].length;i++){
					

						if(data["addressList"][i]["def"]=="1"){
							htmlStr += '<li class="on">';
						}else{
							htmlStr += '<li>';
						}
						
						 if(base.getFromPage()=="suborder"){
							 
								htmlStr += '<a href=javascript:$ldh_user.setDefaultAddress("'+data["addressList"][i]["addressId"]+'")>';

						 }else{
							 
								//htmlStr += '<a href=javascript:$ldh_user.loadAddress("'+data["addressList"][i]["addressId"]+'")>';
							 
							 htmlStr += '<a href='+ctx+'/h5/editAddress/'+data["addressList"][i]["addressId"]+'.shtml>';

						 }
						htmlStr += '<h3><span>'+data["addressList"][i]["shipName"]+'</span><span>'+data["addressList"][i]["shipMobile"]+'</span></h3>';
						htmlStr += '<p>'+data["addressList"][i]["memo"]+'</p>';
						htmlStr += '</a>';
						htmlStr += '</li>';
				}
				
				
				$("#ldhMyAdress .my_address ul").html(htmlStr);
			}else{
				
			}
		}))().start();
		
	};
	
	//保存收货地址
	exports.saveAddress=function(type){
		
		var provinceId=$ldh_base.getCookie("provinceId");
		var cityId=$ldh_base.getCookie("cityId");
		var regionId=$ldh_base.getCookie("regionId");
		var ship_address="";
		var ship_mobile="";
		var shipName="";
		var memo="";
		var def = 0;
		var shipZip="",shipTel="";
		var params;
		var def = 0;
		if(type=="0"){
			ship_address=$("#ldhNewAdress input[name=ship_address]").val();
			ship_mobile=$("#ldhNewAdress input[name=ship_mobile]").val();
			shipName=$("#ldhNewAdress input[name=shipName]").val();
			memo=$("#ldhNewAdress .new_address .li_click span").html()+" "+ship_address;
			if($("#ldhNewAdress .setting_address input[name=def]").is(":checked")){
				def = 1;
			}
		}else{
			ship_address=$("#ldhEditAdress input[name=ship_address]").val();
			ship_mobile=$("#ldhEditAdress input[name=ship_mobile]").val();
			shipName=$("#ldhEditAdress input[name=shipName]").val();
			memo=$("#ldhEditAdress .new_address .li_click span").html()+" "+ship_address;
			if($("#ldhEditAdress .setting_address input[name=def]").is(":checked")){
				def = 1;
			}
		}
		
		if(validate.isNull(shipName)){
		   showTips("收货人不能为空");
		   return;
		}
		if(validate.isNull(provinceId)){
			showTips("请选择省份");
		   return;
		}
		if(validate.isNull(cityId)){
			showTips("请选择城市");
		   return;
		}
		if(validate.isNull(regionId)){
			showTips("请选择区域");
		   return;
		}
		if(validate.isNull(ship_address)){
			showTips("请填写详细地址");
		   return;
		}
		if(!validate.isMobile(ship_mobile)){
			showTips("请填写正确的手机号码");
			   return;
			}
		
		
		
		
		
	
		
		if(type=="0"){
			params={
					"userId":base.getCookie("userId"),
					"provinceId":provinceId,
					"cityId":cityId,
					"regionId":regionId,
					"memo":memo,
					"shipName":shipName,
					"shipMobile":ship_mobile,
					"street":ship_address,
					"def":def,
					"loginSign":$ldh_base.getCookie("loginSign"),
					"sign":MD5($ldh_base.getCookie("loginSign")+base.getCookie("userId")+provinceId+cityId+regionId+shipZip+shipTel+ship_mobile+def)
				};
		}else{
			
			params={
					"addressId":base.getCookie("addressId"),
					"userId":base.getCookie("userId"),
					"provinceId":provinceId,
					"cityId":cityId,
					"regionId":regionId,
					"memo":memo,
					"shipName":shipName,
					"shipMobile":ship_mobile,
					"street":ship_address,
					"def":def,
					"loginSign":$ldh_base.getCookie("loginSign"),
					"sign":MD5($ldh_base.getCookie("loginSign")+base.getCookie("userId")+base.getCookie("addressId")+provinceId+cityId+regionId+shipZip+shipTel+ship_mobile+def)
				};
		}
		
		//this.validateSign(getLoginSign(),getUserId(),addressId,provinceId,cityId,regionId,shipZip,shipTel,mobile,def,flag,lng,lat);
		//this.validateSign(getLoginSign(),getUserId(),provinceId,cityId,regionId,shipZip,shipTel,mobile,def,lng,lat);
		

		base.showLoading();

		eval(Wind.compile("async", function() {
			var data;
			if(type=="0"){
				
				data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Address/saveAddress.do", params));

			}else{
				
				data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Address/updateAddress.do", params));

			}
			
			if(data.code == "1"){
				
				  if(type=="1"){
					  showTips("编辑成功");				 
				  }else{
					  showTips("添加成功");
				  }
				  
					
				  if(base.getFromPage()=="suborder"){
					  	/*base.showDiv("#ldhOrder");
					  	//$("#ldhOrder").show();
					  	//$("#ldhNewAdress").hide();
					  	var htmlStr="";
						htmlStr += '<a data-transition="none" href="#ldhMyAdress">';
						htmlStr += '<h3><span>'+shipName+'</span><span>'+ship_mobile+'</span></h3>';
						htmlStr += '<p>'+memo+'</p></a>';
						$ldh_order.setAddressId(data["addressId"]);*/
					  //base.showDiv("?cartIds="+base.getParameter("cartIds")+"#ldhOrder");
					  
					  window.location.href=ctx+"/h5/suborder/"+base.getParameter("cartIds")+".shtml";
					  
				  }else{
					 /* base.showDiv("#ldhMyAdress");
					  exports.getMyAddressList();*/
					  
					  window.location.href=ctx+"/h5/address.shtml"
				  }
				  	$ldh_base.clearCookie("addressId");
				    $ldh_base.clearCookie("ship_address");
			 		$ldh_base.clearCookie("ship_mobile");
			 		$ldh_base.clearCookie("shipName");
			 		$ldh_base.clearCookie("provinceId");
			 		$ldh_base.clearCookie("cityId");
			 		$ldh_base.clearCookie("regionId"); 
			 		$ldh_base.clearCookie("provinceName");
			 		$ldh_base.clearCookie("cityName");
			 		$ldh_base.clearCookie("regionName");
				
			}else{
				
				
				showTips(data.message);
			}
			
			base.cancelLoading();
						
			
		}))().start();
		
	};
	//设为默认地址
	exports.setDefaultAddress=function(addressId){
		base.showLoading();
		var params={
				addressId:addressId,
				userId:$ldh_base.getCookie("userId"),
				loginSign:$ldh_base.getCookie("loginSign"),
				sign:MD5($ldh_base.getCookie("loginSign")+$ldh_base.getCookie("userId")+addressId)
			};

		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Address/updateDefaultAddress.do", params));

			if(data.code == "1"){
				//base.showDiv("?cartIds="+base.getParameter("cartIds")+"#ldhOrder");
				
				window.location.href=ctx+"/h5/suborder/"+base.getParameter("cartIds")+".shtml";
			}else{
				
			}
			
			$ldh_base.clearCookie("fromPage");
			$ldh_base.clearCookie("cartIds");
			base.cancelLoading();
		}))().start();
		
		
	}
	
	//删除收货地址
	exports.deleteAddress=function(addressId){
		
		var params={
			"addressId":addressId
		};
		
		eval(Wind.compile("async", function() {

			var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Address/delAddress.do", params));
			
			if(data.code == "1"){
				
				 exports.getMyAddressList();
				
			}else{
				
				
			}
			
			
		}))().start();
	};
	
	//加载收货地址,用户编辑
	exports.loadAddress=function(addressId){
		
		base.showLoading();
	/*	
		$("#ldhEditAdress input[name=ship_address]").val("loading...");
		$("#ldhEditAdress input[name=ship_mobile]").val("loading...");
		$("#ldhEditAdress input[name=shipName]").val("loading...");
		$("#ldhEditAdress .new_address .li_click span").html("loading...");
		*/
		//base.showDiv("#ldhEditAdress");
		
		//exports.setAddressId(addressId);
				
		
		
		
		var params={
				"userId":base.getCookie("userId"),
				"addressId":addressId,
				"loginSign":$ldh_base.getCookie("loginSign"),
				"sign":MD5($ldh_base.getCookie("loginSign")+base.getCookie("userId")+addressId)
			};
		
			eval(Wind.compile("async", function() {

				var data= $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Address/loadAddress.do", params));
				
				if(data.code == "1"){
					
					/*provinceId=data["address"]["provinceId"];
					cityId=data["address"]["cityId"];
					regionId=data["address"]["regionId"];*/
					
					$("#ldhEditAdress input[name=ship_address]").val(data["address"]["street"]);
					$("#ldhEditAdress input[name=ship_mobile]").val(data["address"]["shipMobile"]);
					$("#ldhEditAdress input[name=shipName]").val(data["address"]["shipName"]);
					$("#ldhEditAdress .new_address .li_click span").html(data["address"]["provinceName"]+"&nbsp;&nbsp;"+data["address"]["cityName"]+"&nbsp;&nbsp;"+data["address"]["regionName"]);
					$("#ldhEditAdress .setting_address input[name=def]").attr("checked",true);
					
					
			 	    $ldh_base.setCookie("ship_address",data["address"]["street"]);
			 		$ldh_base.setCookie("ship_mobile",data["address"]["shipMobile"]);
			 		$ldh_base.setCookie("shipName",data["address"]["shipName"]);
			 		$ldh_base.setCookie("provinceId",data["address"]["provinceId"]);
			 		$ldh_base.setCookie("cityId",data["address"]["cityId"]);
			 		$ldh_base.setCookie("regionId",data["address"]["regionId"]); 
			 		$ldh_base.setCookie("addressId",addressId); 
			 		
					
				}else{
					
					
				}
				base.cancelLoading();
				
			}))().start();
		
	};
	
	/**
	 * 查询所有省份
	 */
	exports.findAllProvince=function(){
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findAllProvince.do", ""));
		
					findAllProvinceCallBack(data);

				}))().start();
		
	};
	
	/**
	 * 查询所有省份_回调函数
	 */
	function findAllProvinceCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
			
			//htmlStr+='<li><a href=javascript:$ldh_user.setProvinceId("'+data[i].PROVINCE_ID+'","'+data[i].PROVINCE_NAME+'")>'+data[i].PROVINCE_NAME+'</a></li>';
			
			htmlStr+='<dd onclick=$ldh_user.setProvinceId("'+data[i].PROVINCE_ID+'","'+data[i].PROVINCE_NAME+'")><p>'+data[i].PROVINCE_NAME+'</p></dd>';
			
			//htmlStr+='<dd onclick=window.location.href="'+ctx+'/h5/cityList/'+data[i].PROVINCE_ID+'.shtml"><p>'+data[i].PROVINCE_NAME+'</p></dd>';
		}
		
		$("#selectProvince dl").html(htmlStr);
	}
	
	/**
	 * 根据省份查询城市
	 */
	exports.findCityByProvince=function(provinceId){
		
		var params={
			provinceId:provinceId
		};
		
		eval(
				Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findCityByProvince.do",params));
					
					findCityByProvinceCallBack(data);

				}))().start();
	}
	
	/**
	 * 根据省份查询城市
	 */
	function findCityByProvinceCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
						
			
			htmlStr+='<dd onclick=$ldh_user.setCityId("'+data[i].CITY_ID+'","'+data[i].CITY_NAME+'")><p>'+data[i].CITY_NAME+'</p></dd>';
			//htmlStr+='<dd onclick=window.location.href="'+ctx+'/h5/regionList/'+data[i].CITY_ID+'.shtml&provinceId='+provinceId+'"><p>'+data[i].CITY_NAME+'</p></dd>';
		}
		
		$("#selectCity dl").html(htmlStr);
	}
	
	
	/**
	 * 根据城市查询区域
	 */
	 exports.findRegionByCity=function(cityId){
		
		var params={
				cityId:cityId
			};
		
		eval(Wind.compile("async", function() {

					var data = $await(async.DDF_AsyncRequest("POST", ctx
							+ "/shopweb/SysParam/findRegionByCity.do",params));
					
					findRegionByCityCallBack(data);

				}))().start();
	}
	
	/**
	 * 根据城市查询区域_回调函数
	 */
	function findRegionByCityCallBack(data){
		
		var htmlStr="";
		
		for(var i=0;i<data.length;i++){
			
			//htmlStr+='<li><a href=javascript:$ldh_user.setRegionId("'+data[i].REGION_ID+'","'+data[i].REGION_NAME+'")>'+data[i].REGION_NAME+'</a></li>';
			htmlStr+='<dd onclick=$ldh_user.setRegionId("'+data[i].REGION_ID+'","'+data[i].REGION_NAME+'")><p>'+data[i].REGION_NAME+'</p></dd>';
			
			//htmlStr+='<dd onclick=window.location.href="'+ctx+'/h5/addAddress.shtml?provinceId='+provinceId+'&cityId='+cityId+'&regionId='+data[i].REGION_ID+'"><p>'+data[i].REGION_NAME+'</p></dd>';

		}
		
		$("#selectRegion dl").html(htmlStr);
		
	}
	
	exports.setAddressId=function(addressId){
		
		//this.addressId=addressId;
	
		$("#ldhEditAdress input[name='addressId']").val(addressId);
	};
	
	exports.getAddressId=function(){
		
		return $("#ldhEditAdress input[name='addressId']").val()==null?"":$("#ldhEditAdress input[name='addressId']").val();
		
	};
	
	//var provinceId=null,cityId=null,regionId=null;
	
	exports.setProvinceId=function(provinceId,provinceName){
		
		$ldh_base.setCookie("_provinceName",provinceName);
		window.location.href=ctx+'/h5/cityList/'+provinceId+'.shtml';
		
		
	};
	
	exports.getProvinceId=function(){
		
		return provinceId==null?"":provinceId;
		
	};
	
	exports.setCityId=function(cityId,cityName){
		
		$ldh_base.setCookie("_cityName",cityName);
		
		window.location.href=ctx+'/h5/regionList/'+cityId+'.shtml&provinceId='+provinceId;
	};
	
	exports.getCityId=function(){
		
		return cityId==null?"":cityId;
		
	};
	
	
	exports.setRegionId=function(regionId,regionName){
		$ldh_base.setCookie("provinceName",$ldh_base.getCookie("_provinceName"));
		$ldh_base.setCookie("cityName",$ldh_base.getCookie("_cityName"));
		$ldh_base.setCookie("regionName",regionName);
		if(validate.isNull($ldh_base.getCookie("addressId"))){
			window.location.href=ctx+'/h5/addAddress.shtml?provinceId='+provinceId+'&cityId='+cityId+'&regionId='+regionId;

		}else{
			window.location.href=ctx+'/h5/editAddress/'+$ldh_base.getCookie("addressId")+'.shtml&provinceId='+provinceId+'&cityId='+cityId+'&regionId='+regionId;

		}
		
		
	/*	if(base.getOpt()=='add'){
			
			$ldh_base.showDiv("#ldhNewAdress");
			
			$("#ldhNewAdress .new_address .li_click span").html($("#selectCity .header_fixed h1").html()+"&nbsp;&nbsp;"+$("#selectRegion .header_fixed h1").html()+"&nbsp;&nbsp;"+regionName);

		}else{
			$ldh_base.showDiv("#ldhEditAdress");
			
			$("#ldhEditAdress .new_address .li_click span").html($("#selectCity .header_fixed h1").html()+"&nbsp;&nbsp;"+$("#selectRegion .header_fixed h1").html()+"&nbsp;&nbsp;"+regionName);

		}
		*/
		
	};
	
	exports.getRegionId=function(){
		
		return regionId==null?"":regionId;
		
	};
	
	
	//定时提示信息
	var tips_task = eval(Wind.compile("async", function (divId) {
		
	    $await(Wind.Async.sleep(2000));
	   
	    $(divId).hide();
	    
	    
	}));
	
	var task = eval(Wind.compile("async", function (divId) {
	    $await(tips_task(divId));
	}));
	
	//验证码倒计时
	var wait = 90;
	
	var tips_task_mobile = eval(Wind.compile("async", function (btnId) {
		wait--;
	    $await(Wind.Async.sleep(1000));
	    if(wait==0){
	    	//倒计时完成,发送验证码按钮生效
	    	$(btnId).attr("disabled", false);
	    	$(btnId).val("免费获取验证码");
	    	
	    }else{
	    	
	    	$(btnId).val(wait + "秒后重新获取");
	    }
	    
	}));
	
	var task_mobile = eval(Wind.compile("async", function (btnId) {
	    $await(tips_task_mobile(btnId));
	    if(wait>0){
	    	task_mobile(btnId).start();
	    }else{
	    	wait=90;
	    }
	}));
	
});

